<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xwk="http://http://code.google.com/p/xworks"
    xmlns:inc="http://code.google.com/p/xworks..includes" 
    exclude-result-prefixes="xwk inc"/>
    
<xsl:variable name="effects" select="document('../documents.xml/effects.xml')/effects/effect" />

	<xsl:template match="node() | @*" mode="inc:snippets">
		<xsl:copy>
			<xsl:apply-templates select="@*" mode="inc:snippets"/>
			<xsl:apply-templates select="node()" mode="inc:snippets"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="@*[name()='effect']"/>

	<xsl:template match="a" mode="inc:snippets">
		<a href="{@href}">
			<xsl:value-of select="."/>
			<xsl:if test="@effect">
				<xsl:call-template name="effects">
					<xsl:with-param name="name">
						<xsl:value-of select="@effect"/>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
		</a>
		<xsl:if test="@posted">
			<xsl:comment>
				<xsl:value-of select="concat('Posted On: ', @posted)"/>
			</xsl:comment>
		</xsl:if>

	</xsl:template>


	<xsl:template name="effects">
		<xsl:param name="name"/>
		<xsl:apply-templates select="$effects[@name=$name]" mode="inc:snippets" />
	</xsl:template>

	<xsl:template match="effect" mode="inc:snippets">
		<img src="{image/@src}" border="0">
			<xsl:if test="image/width">
				<xsl:attribute name="width">
					<xsl:value-of select="image/width"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="image/height">
				<xsl:attribute name="height">
					<xsl:value-of select="image/height"/>
				</xsl:attribute>
			</xsl:if>
		</img>
	</xsl:template>

</xsl:stylesheet> 

